<?php
/**
 * @action 登录日志控制器
 * @authors guo (guomingliangphp@163.com)
 * @date    2014-01-13 17:49:15
 * @version $Id$
 */
class LogAction extends CommonAction {

    //指定代理商下的用户的登录记录(总代理看到的是所有的用户的登录记录)
    public function userloglist(){

        $names=R("Agent/userlist");
        $this->names=$names;

        $log=M("login");
        $agentId=$_SESSION['agent']['id'];
        if($agentId!=1){
           $userStr=R("Agent/userlist");
            $condition['username']=array("exp","in($userStr)");
        }
//按指定的条件进行查询
        if(I("get.userName")){
            $userName=I("get.userName");
            $this->userName=$userName;
            if($agentId!=1){
                $condition['username']=array(array("like","%$userName%"),array("exp","in($userStr)"));
            }else{
                $condition['username']=array("like","%$userName%");
            }
            if(I("get.stime")){
                $stime=I("get.stime");
                $this->stime=$stime;
                if(I("get.etime")){
                    $etime=I("get.etime");
                    $this->etime=$etime;
                    $etime=date('Y-m-d',strtotime('+1 day',strtotime($etime)));
                    $condition['addtime']=array("between","$stime,$etime");
                }
            }
        }
        import("ORG.Util.Page");
        $pagenumber=10;
        $list=$log->page($_GET['p'])->where($condition)->order('id desc')->limit($pagenumber)->select();
        if($list==NULL){
            $this->error("用户不存在或在该时间段内无登录记录！","__URL__/userloglist");
        }
        $totalnum= count($log->where($condition)->select());
        $this->assign("list",$list);
        $page=new Page($totalnum,$pagenumber);
        $page->setConfig("prev","上一页");
        $page->setConfig("next","下一页");
        $page->setConfig("first","首页");
        $page->setConfig("last","末页");
        $page->setConfig("theme","<span class=pageinfo> <u></u>当前%nowPage%/%totalPage%页</span>
                                     %first% %upPage%   %linkPage%  %downPage% %end%");
        $pageshow=$page->show();
        $this->assign("pageshow",$pageshow);
        $this->display();
    }
}